<?php
/**
 * Created by PhpStorm.
 * User: td
 * Date: 15/1/12
 * Time: 下午11:14
 */

namespace Home\Controller;
use Think\Controller;

class FetcherController extends Controller {

    //接活首页－未登录
    public function index(){

        $this->assign('curNav', 0);
        if(isset($_SESSION['loginUser'])){
            //获取有无未读消息
            $message_db = D("Message");
            $message_result = $message_db->getIsRead($_SESSION['loginUser']['user_id']);
            if(is_array($message_result)){
                session('is_read',1);
            }else{
                session('is_read',2);
            }
            $this->display("Fetcher/search");
        } else {
            $this->display("Fetcher/index");
        }
    }

    //pc端未登录
    public function indexPC(){
        //loginStatus();
        $this->assign('curNav', 0);
        if(isset($_SESSION['loginUser'])){
            $this->theme('PC')->display('Fetcher/fetcher');
        } else {
            $this->theme('PC')->display('Fetcher/index');
        }
    }

    //接活首页－精准搜索
    public function search(){
        $this->assign('curNav', 0);
        if(isset($_SESSION['loginUser'])){
            $this->display("Fetcher/search");
        }else{
            $this->display("Login/index");
        }
    }

    //接活首页动态信息获取-未登录
    public function fetcherIndex(){
        $jobs = $_GET['jobs'];
        $duration = $_GET['duration'];
        if (IS_GET) {
            $mission_db = D('Mission');
            $result = $mission_db->getMInfo($jobs, $duration);
            if ($result) {
                // dump($result);
                $this->success('获取信息成功', $result);
            } else {
                $this->error('获取信息失败!');
            }
        }
    }

    //接活首页用户默认选项－岗位＋时限
    public function fetcherIndexJobsDuration(){
        if(IS_GET){
            $user_id = $_SESSION['loginUser']['user_id'];
            $user_ext_db = D('UserExt');
            $user_ext_result = $user_ext_db->getUserJobsDuration($user_id);
            if(is_array($user_ext_result)){
                $this->success('获取信息成功',$user_ext_result);
            }else{
                $this->error('获取信息失败');
            }
        }else{
            $this->error('错误方法');
        }
    }

    //接活首页动态信息获取－登陆
    public function fetcherIndexLogin(){
        if(isset($_SESSION['loginUser'])){
            $keyword = $_GET['keyword'];
//            dump($keyword);
            $jobs = $_GET['jobs'];
            $duration = $_GET['duration'];
            $page = $_GET['page'];
            $row =  $_GET['row'];
           // $page = 2;
            //$row = 2;
            if(IS_GET){
                $mission_db = D('Mission');
                $result = $mission_db->getMInfoLoginPage($keyword,$jobs, $duration,$page,$row);
                if ($result) {
                    // dump($result);
                    $this->success('获取信息成功', $result);
                } else {
                    $this->error('获取信息失败!');
                }
            }
        }else{
            $this->error('请登陆系统',U('Login/index'));
        }
    }

    //岗位信息
    public function jobsInfo(){
//        if(isset($_SESSION['loginUser'])){
            $station_db = D('Station');
            $station_result = $station_db->getJobsInfo();
            if($station_result){
                $this->success('获取信息成功',$station_result);
            }else{
                $this->error('获取信息失败');
            }
//        }else{
//            $this->error('请登陆系统',U('Login/index'));
//        }
    }

    //test
    public function test(){

//        $test_db = D('Mission');
//        $test_result = $test_db->getMInfoLogin($keyword,$jobs,$duration);
//        dump($test_result);

//        $station_db = D('Station');
//        $station_result = $station_db->getJobsInfo();
//        dump($station_result);

        $user_id = $_SESSION['loginUser']['user_id'];
        dump($user_id);
        $user_ext_db = D('UserExt');
        $user_ext_result = $user_ext_db->getUserJobsDuration($user_id);
        if(is_array($user_ext_result)){
            dump($user_ext_result);
        }
    }

} 